<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use app\modules\Product\models\Product;
use app\models\Supplier;
use yii\widgets\LinkPager;
use kartik\datetime\DateTimePicker;

$product = Product::findOne($product_id); 
$this->title =  $product->name; 
?>
<style type="text/css">
	table tr td p font{ color:#666;margin-right:10px;}
</style>
<div class="order-index">
	
    <h2 class="page-header"><small>后返金额列表 : <?= Html::encode($this->title) ?>&nbsp;&nbsp;<?= $product->go_time ?></small></h2>
	<table class="table " style="margin-top:15px;font-size:12px;">
		<thead><tr> <th>基本信息</th> <th>联系人</th> <th>舱房信息</th>  <th>金额</th> <th>状态</th><th></th> </tr></thead>
		<tbody>
		<?php foreach($dataProvider->getModels() as $m){ ?>
			<tr class="style-<?= $m->status ?> <?= ($m->isRelation > 1) ? 'style-relation' : '' ?>">
				<td class="col-md-2">
					<p><font>销售</font> <?= isset($m->member->id) ? $m->member->profile->name : '(未设置)'  ?> </p>
					<p><font>创建时间</font> <?= Yii::$app->formatter->asDate($m->created_at)?></p>
					<p><font>更新时间</font> <?= Yii::$app->formatter->asRelativeTime($m->updated_at)?></p>
					<p><font>订单号</font> <?= $m->code ?></p>
				</td>

				<td class="col-md-2">
					<p><font>联系人</font> <?= $m->username ?></p>
					<p><font>电  话</font>  <?= $m->phone ?></p>
					<p><font>公  司</font>  <?= $m->company ?></p>
					<p><font>备  注</font>  <?= $m->remark ?></p>
				</td>

				<td class="col-md-4">
					<?php 
						if($m->product->stock == 1){ // 国内航线  $m -> Order
							if($m->status <10){
								
								$orderRoom = $m->room;
							}else{
							
								$orderRoom = $m->roomAll;
							}	
							foreach($orderRoom as $room){ // orderRoom
								echo "<p>";
            					echo $room->productRoom->room->name;
            					echo '  '.$room->productRoom->room->code;
            					echo '  '.$room->productRoom->people .'人间&nbsp;&nbsp;';
								echo " &nbsp;&nbsp;&nbsp;";
								echo "后返上限 :  <font style='color:#FF4500'>".Yii::$app->formatter->asCurrency($room->productRoom->commiss_price)."</font> / 人";
								echo "</p>";
							}
						}elseif($m->product->stock == 2){ // 海外航线
							$t = json_decode($m->product->rooms, true);	
							if($m->status <10){
								$orderRoom = $m->room;
							}else{
								$orderRoom = $m->roomAll;
							}	

							foreach($orderRoom as $room){ // orderRoom
								echo "<p>";
            					print_r($t[$room->room_id]['name']);
								echo " &nbsp;&nbsp;&nbsp;";
								echo "后返上线 :  <font style='color:#FF4500'>".Yii::$app->formatter->asCurrency($room->productRoom->commiss_price)."</font> / 人";
								echo "</p>";
							}
						}
					?>
				</td>


				<td class="col-md-2">
					<p><font>总金额</font> <b style="color:<?= ($m->status == 10) ? '#CCC;' : '#FF4500;' ?>"><?= Yii::$app->formatter->asCurrency($m->price) ?></b></p>
					<p><font>后返</font> <?= Yii::$app->formatter->asCurrency($m->commiss) ?></p>
					<p><font>后返上限</font> <?= Yii::$app->formatter->asCurrency($m->maxCommiss) ?></p>
				</td>
				<td class="col-md-1">
					<p><?= Yii::$app->params['order_status'][$m->status] ?></p>
					<p><a class="fa fa-calendar-check-o" href="/order/order/log?id=<?= $m->id?>" title='操作记录' data-toggle='modal' data-target='.log-modal'></a></p>
					<?php if($m->is_merge == 2){ ?>
						<p><i class="fa fa-handshake-o" <?= empty($m->merge_id) ? '' : "style=color:red;" ?> title='拼房标识' ></i></p>
					<?php } ?>
				</td>

				<td>
					<?php if($m->status < 10){ ?>
						<p>&nbsp;</p><p><a href="/order/order/view?id=<?= $m->id?>" target="_blank">详情</a></p>
					<?php } ?>
				</td>
			</tr>
			<?php if($m->nextIsRelation == 1){ ?>
			<tr class="col-md-12" style="background-color: #FFFFFF;height:10px;">
			</tr>
			<?php }?>
		<?php } ?>
		</tbody>
	</table>

	<?= LinkPager::widget(['pagination' => $dataProvider->pagination]); ?>
</div>


<div class="modal fade log-modal"   role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog " role="document" style="width:740px;">
      <div class="modal-content">
	 		<!-- 嵌入内容 --> 
	  </div>
  </div>
</div>

<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">
// 清除模态框缓存
$(".log-modal").on("hidden.bs.modal", function() {
	$(this).removeData("bs.modal");
});

$(".config-modal").on("hidden.bs.modal", function() {
    $(this).removeData("bs.modal");
});
</script>
<?php app\components\JsBlock::end() ?>   
